import { HttpMsgID } from "../data/GameConfig";
import MyFetch from "./MyFetch";

export default class HttpApi {
    public static async login(data: any) {
        return await MyFetch.post<any>(HttpMsgID.login, data);
    }
    public static async payNotify(data: CSPayNotify) {
        await MyFetch.waitSessionId();
        return await MyFetch.post<SCPayNotify>(HttpMsgID.payNotify, data);
    }
    public static async bundleConfig(env: string): Promise<IBundleConfig[]> {
        const url = 'http://solitaire.test.woohooslots.com:8080/Upload/getConfig?path=' + env;
        const res = await MyFetch.getExternal<any>(url);
        console.log('res', res);
        if (res.code == 2) {
            return [{
                bundleName: 'res',
                version: '1.0.0'
             }, {
                bundleName: 'config',
                version: '1.0.0'
             },];
        }
        return res.data[0].config as IBundleConfig[];
    }
}

export interface CSPayNotify {
    pid: string; //内部订单号 (时间戳+Uid)
    orderId: string; //支付订单号
    price: number; //订单金额 单位 $ (美元)
    payChannel: number; //支付渠道
    payParams: string; //支付参数 json格式 { "productId":"商品sku", "token":"支付校验token" }
    reportParams: string; //上报参数 json格式 如需后端上报则传递，否则不传
}

export interface SCPayNotify {
    pid: string; //订单号
    orderId: string; //订单号
    channel: number; //支付渠道
    isTest: boolean; //是否测试
    isRepeat: number; // 0-未重复校验 1-重复校验 
}

export interface IBundleConfig {
    bundleName: string;
    version: string;
}
